package com.example.producer.mq;

import com.example.producer.utils.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;

/**
 * 生产者
 */
@Component
@EnableScheduling
public class Producer {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue sendQueue;

    @Scheduled(fixedDelay = 5000)
    public void send() {
        System.out.println("测试消息队列, 时间：" + DateTimeUtil.getCurrentDateTime());
        jmsMessagingTemplate.convertAndSend(sendQueue, "测试消息队列, 时间：" + DateTimeUtil.getCurrentDateTime());
//        jmsMessagingTemplate.send(queue, "测试消息队列" + System.currentTimeMillis());
//        System.out.println("test");
    }
}
